<?php
    namespace App\Http\Controllers\home;
    use App\Http\Controllers\Controller;
    use Illuminate\Support\Facades\Input;
    use DB;
    class CateController extends Controller{
      	public function cate($cate_name){
          $cname = DB::table('mo_cate')->where(array('cate_name'=>$cate_name))->get();
          foreach ($cname as $k => $v) {
            $cname1[] = $v->parent_id;
            $cname2[] = $v->cate_id;
          }
          $c_c_one = DB::table('mo_cate')->where(array('s_id'=>0))->get();
          $c_name = DB::table('mo_cate')->where(array('parent_id'=>0))->get();
          if($cname1[0] == 0){
            foreach ($c_c_one as $k => $v) {
              $v->p_name = DB::table('mo_cate')->where(array('s_id'=>$v->cate_id,'parent_id'=>$cname2))->get();
            }
            $data = DB::table('mo_goods')
              ->leftJoin('mo_cate', 'mo_goods.g_cate_id', '=', 'mo_cate.cate_id')
              ->where(array('g_status'=>1,'cate_name'=>$cate_name))
              ->orWhere(array('g_status'=>1,'parent_id'=>$cname2))
              ->get();
            return view('home.cate.cate',array('data'=>$data,'c_c_one'=>$c_c_one,'cate_name'=>$cate_name,'c_name'=>$c_name,'c_id'=>$cname2));
          }else{
            $data = DB::table('mo_goods')
              ->leftJoin('mo_cate', 'mo_goods.g_cate_id', '=', 'mo_cate.cate_id')
              ->where(array('g_status'=>1,'cate_name'=>$cate_name))
              ->get();
            foreach ($c_c_one as $k => $v) {
              $v->p_name = DB::table('mo_cate')->where(array('s_id'=>$v->cate_id,'parent_id'=>$cname1))->get();
            }
            return view('home.cate.cate',array('data'=>$data,'c_c_one'=>$c_c_one,'cate_name'=>$cate_name,'c_name'=>$c_name,'c_id'=>$cname1));
          }
        }
    }
?>